<?php

namespace App\Filament\Resources\BookResource\Pages;

use App\Filament\Resources\BookResource;

use App\Jobs\ImportBookChapter;
use App\Models\Book;
use App\Service\BqsService;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;


class ListBooks extends ListRecords
{
    protected static string $resource = BookResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\CreateAction::make(),

        ];
    }

    /**
     * @throws \Exception
     */
    public static function importSection(Book $record): void
    {
//       $list = BqsService::searchByName($record->title);
//       foreach ($list as $item) {
//           $record->chapters()->create([
//               'chapter_title' => $item['name'],
//               'chapter_link' => $item['url'],
//           ]);
//       }
        ImportBookChapter::dispatch($record);
       Notification::make('导入成功')
           ->title('已加入更新队列')
           ->body('请稍后查看')
           ->success()
           ->send();
    }

}
